package com.gitee.leijin.rbac.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gitee.leijin.rbac.entity.SysUser;
import com.gitee.leijin.rbac.exception.BizException;
import com.gitee.leijin.rbac.model.SysUserDTO;
import com.gitee.leijin.rbac.security.SecurityUser;
import com.gitee.leijin.rbac.service.SysUserService;
import com.gitee.leijin.rbac.mapper.SysUserMapper;
import org.aspectj.weaver.ast.Var;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

/**
 * @author 24844
 * @description 针对表【sys_user(用户信息表)】的数据库操作Service实现
 * @createDate 2024-06-30 12:04:40
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {



    @Override
    public UserDetails loadUserByUsername(String username) {

        LambdaQueryWrapper<SysUser> wrapper = Wrappers.<SysUser>lambdaQuery().
                eq(SysUser::getUserName, username);
        SysUser sysUser = getOne(wrapper);
        if (sysUser == null) {
            throw new BizException("用户名或密码错误。");
        }
        SecurityUser securityUser = new SecurityUser();
        securityUser.setSysUser(sysUser);
        return securityUser;
    }
}




